#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      sp41822
#
# Created:     25/03/2013
# Copyright:   (c) sp41822 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------
from HTMLParser import HTMLParser
import urllib, os, zipfile, sys, urllib2
from PyQt4 import QtGui, QtCore
import osmand_datas
import threading

class dataThread(QtCore.QThread):
    tick=QtCore.pyqtSignal(int, name="ninja")
    def __init__(self,query,ui):
        super(dataThread,self).__init__()
        self.query=query
        self.ui=ui
    def run(self):
        print("run")
        osmand_datas.gogogo(str(self.query), self.ui, self, self.tick)
        print("endrun")

class myosmandui(QtGui.QWidget):
    def __init__(self):
        super(myosmandui, self).__init__()
        self.theUI()

    def theUI(self):
        lay = QtGui.QGridLayout()
        self.setGeometry(150,150,200,200)
        self.setWindowTitle("titre de la fenetre")
        self.setLayout(lay)
        btn = QtGui.QPushButton('gogogo',self)
        btn.move(0,30)
        self.qle = QtGui.QLineEdit("test",self)
        self.qle.move(0,60)
        query = QtGui.QLabel("test",self)
        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(0,90,400,20)
        self.connect(btn, QtCore.SIGNAL('clicked()'), self.stuff)

        self.show()
    def stuff(self):
        print self.qle.text()
        self.t=dataThread(self.qle.text(),self)
        #self.connect(t,QtCore.SIGNAL("pbar"),self.pbar)
        self.t.tick.connect(self.pbar)
        self.t.start()

    def pct(self,pourcentage):
        self.qle.setText(pourcentage)
    def pbar(self,progress):
        try:
            if self.pb.value() != progress:
                self.pb.setValue(progress)
        except:
            print("ouch")

def main():
    app=QtGui.QApplication(sys.argv)
    my = myosmandui()
    sys.exit(app.exec_())

    #osmand_datas.gogogo("guyane")


if __name__ == '__main__':
    main()
